package com.lanou.wuyou.one.guide;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.wuyou.one.MainActivity;

/**
 * Created by dllo on 17/3/9.
 */

public class Async extends AsyncTask<Integer,String,String>{
    private TextView textView;
    private Context context;
    private GuideActivity guideActivity;

    public void setGuideActivity(GuideActivity guideActivity) {
        this.guideActivity = guideActivity;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public void setTextView(TextView textView) {
        this.textView = textView;
    }

    //耗时操作
    @Override
    protected String doInBackground(Integer... params) {
        //引导页倒数
        for (int i = 5; i > 0; i--) {
            try{
                //间隔1秒
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //更新主线程UI,刷新秒数
            publishProgress(String.valueOf(i));
        }
        return null;
    }

    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
        textView.setText(values[0]);
    }

    //doInBackground执行后执行
    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        context.startActivity(new Intent(context, MainActivity.class));
    }

    @Override
    protected void onCancelled(String s) {
        super.onCancelled(s);
    }
}
